﻿using System;
using System.Collections;
using UnityEngine;
using UnityEngine.Events;

namespace Valve.VR.InteractionSystem
{
	// Token: 0x02000654 RID: 1620
	public class Teleport : MonoBehaviour
	{
		// Token: 0x06002918 RID: 10520 RVA: 0x000EE8F0 File Offset: 0x000ECAF0
		public static SteamVR_Events.Action<float> ChangeSceneAction(UnityAction<float> action)
		{
			return new SteamVR_Events.Action<float>(Teleport.ChangeScene, action);
		}

		// Token: 0x06002919 RID: 10521 RVA: 0x000EE900 File Offset: 0x000ECB00
		public static SteamVR_Events.Action<TeleportMarkerBase> PlayerAction(UnityAction<TeleportMarkerBase> action)
		{
			return new SteamVR_Events.Action<TeleportMarkerBase>(Teleport.Player, action);
		}

		// Token: 0x0600291A RID: 10522 RVA: 0x000EE910 File Offset: 0x000ECB10
		public static SteamVR_Events.Action<TeleportMarkerBase> PlayerPreAction(UnityAction<TeleportMarkerBase> action)
		{
			return new SteamVR_Events.Action<TeleportMarkerBase>(Teleport.PlayerPre, action);
		}

		// Token: 0x170004F4 RID: 1268
		// (get) Token: 0x0600291B RID: 10523 RVA: 0x000EE920 File Offset: 0x000ECB20
		public static Teleport instance
		{
			get
			{
				if (Teleport._instance == null)
				{
					Teleport._instance = UnityEngine.Object.FindObjectOfType<Teleport>();
				}
				return Teleport._instance;
			}
		}

		// Token: 0x0600291C RID: 10524 RVA: 0x000EE944 File Offset: 0x000ECB44
		private void Awake()
		{
			Teleport._instance = this;
			this.chaperoneInfoInitializedAction = ChaperoneInfo.InitializedAction(new UnityAction(this.OnChaperoneInfoInitialized));
			this.pointerLineRenderer = base.GetComponentInChildren<LineRenderer>();
			this.teleportPointerObject = this.pointerLineRenderer.gameObject;
			int nameID = Shader.PropertyToID("_TintColor");
			this.fullTintAlpha = this.pointVisibleMaterial.GetColor(nameID).a;
			this.teleportArc = base.GetComponent<TeleportArc>();
			this.teleportArc.traceLayerMask = this.traceLayerMask;
			this.loopingAudioMaxVolume = this.loopingAudioSource.volume;
			this.playAreaPreviewCorner.SetActive(false);
			this.playAreaPreviewSide.SetActive(false);
			float x = this.invalidReticleTransform.localScale.x;
			this.invalidReticleMinScale *= x;
			this.invalidReticleMaxScale *= x;
		}

		// Token: 0x0600291D RID: 10525 RVA: 0x000EEA2C File Offset: 0x000ECC2C
		private void Start()
		{
			this.teleportMarkers = UnityEngine.Object.FindObjectsOfType<TeleportMarkerBase>();
			this.HidePointer();
			this.player = Valve.VR.InteractionSystem.Player.instance;
			if (this.player == null)
			{
				GlobalData.Debug_LogError("Teleport: No Player instance found in map.");
				UnityEngine.Object.Destroy(base.gameObject);
				return;
			}
			this.CheckForSpawnPoint();
			base.Invoke("ShowTeleportHint", 5f);
		}

		// Token: 0x0600291E RID: 10526 RVA: 0x000EEA94 File Offset: 0x000ECC94
		private void OnEnable()
		{
			this.chaperoneInfoInitializedAction.enabled = true;
			this.OnChaperoneInfoInitialized();
		}

		// Token: 0x0600291F RID: 10527 RVA: 0x000EEAA8 File Offset: 0x000ECCA8
		private void OnDisable()
		{
			this.chaperoneInfoInitializedAction.enabled = false;
			this.HidePointer();
		}

		// Token: 0x06002920 RID: 10528 RVA: 0x000EEABC File Offset: 0x000ECCBC
		private void CheckForSpawnPoint()
		{
			foreach (TeleportMarkerBase teleportMarkerBase in this.teleportMarkers)
			{
				TeleportPoint teleportPoint = teleportMarkerBase as TeleportPoint;
				if (teleportPoint && teleportPoint.playerSpawnPoint)
				{
					this.teleportingToMarker = teleportMarkerBase;
					this.TeleportPlayer();
					break;
				}
			}
		}

		// Token: 0x06002921 RID: 10529 RVA: 0x000EEB18 File Offset: 0x000ECD18
		public void HideTeleportPointer()
		{
			if (this.pointerHand != null)
			{
				this.HidePointer();
			}
		}

		// Token: 0x06002922 RID: 10530 RVA: 0x000EEB34 File Offset: 0x000ECD34
		private void Update()
		{
			Hand oldPointerHand = this.pointerHand;
			Hand hand = null;
			foreach (Hand hand2 in this.player.hands)
			{
				if (this.visible && this.WasTeleportButtonReleased(hand2) && this.pointerHand == hand2)
				{
					this.TryTeleportPlayer();
				}
				if (this.WasTeleportButtonPressed(hand2))
				{
					hand = hand2;
				}
			}
			if (this.allowTeleportWhileAttached && !this.allowTeleportWhileAttached.teleportAllowed)
			{
				this.HidePointer();
			}
			else if (!this.visible && hand != null)
			{
				this.ShowPointer(hand, oldPointerHand);
			}
			else if (this.visible)
			{
				if (hand == null && !this.IsTeleportButtonDown(this.pointerHand))
				{
					this.HidePointer();
				}
				else if (hand != null)
				{
					this.ShowPointer(hand, oldPointerHand);
				}
			}
			if (this.visible)
			{
				this.UpdatePointer();
				if (this.meshFading)
				{
					this.UpdateTeleportColors();
				}
				if (this.onActivateObjectTransform.gameObject.activeSelf && Time.time - this.pointerShowStartTime > this.activateObjectTime)
				{
					this.onActivateObjectTransform.gameObject.SetActive(false);
				}
			}
			else if (this.onDeactivateObjectTransform.gameObject.activeSelf && Time.time - this.pointerHideStartTime > this.deactivateObjectTime)
			{
				this.onDeactivateObjectTransform.gameObject.SetActive(false);
			}
		}

		// Token: 0x06002923 RID: 10531 RVA: 0x000EECE8 File Offset: 0x000ECEE8
		private void UpdatePointer()
		{
			Vector3 position = this.pointerStartTransform.position;
			Vector3 forward = this.pointerStartTransform.forward;
			bool flag = false;
			bool active = false;
			Vector3 vector = this.player.trackingOriginTransform.position - this.player.feetPositionGuess;
			Vector3 velocity = forward * this.arcDistance;
			TeleportMarkerBase teleportMarkerBase = null;
			float num = Vector3.Dot(forward, Vector3.up);
			float num2 = Vector3.Dot(forward, this.player.hmdTransform.forward);
			bool flag2 = false;
			if ((num2 > 0f && num > 0.75f) || (num2 < 0f && num > 0.5f))
			{
				flag2 = true;
			}
			this.teleportArc.SetArcData(position, velocity, true, flag2);
			RaycastHit raycastHit;
			if (this.teleportArc.DrawArc(out raycastHit))
			{
				flag = true;
				teleportMarkerBase = raycastHit.collider.GetComponentInParent<TeleportMarkerBase>();
			}
			if (flag2)
			{
				teleportMarkerBase = null;
			}
			this.HighlightSelected(teleportMarkerBase);
			Vector3 vector2;
			if (teleportMarkerBase != null)
			{
				if (teleportMarkerBase.locked)
				{
					this.teleportArc.SetColor(this.pointerLockedColor);
					this.pointerLineRenderer.startColor = this.pointerLockedColor;
					this.pointerLineRenderer.endColor = this.pointerLockedColor;
					this.destinationReticleTransform.gameObject.SetActive(false);
				}
				else
				{
					this.teleportArc.SetColor(this.pointerValidColor);
					this.pointerLineRenderer.startColor = this.pointerValidColor;
					this.pointerLineRenderer.endColor = this.pointerValidColor;
					this.destinationReticleTransform.gameObject.SetActive(teleportMarkerBase.showReticle);
				}
				this.offsetReticleTransform.gameObject.SetActive(true);
				this.invalidReticleTransform.gameObject.SetActive(false);
				this.pointedAtTeleportMarker = teleportMarkerBase;
				this.pointedAtPosition = raycastHit.point;
				if (this.showPlayAreaMarker)
				{
					TeleportArea teleportArea = this.pointedAtTeleportMarker as TeleportArea;
					if (teleportArea != null && !teleportArea.locked && this.playAreaPreviewTransform != null)
					{
						Vector3 b = vector;
						if (!this.movedFeetFarEnough)
						{
							float num3 = Vector3.Distance(vector, this.startingFeetOffset);
							if (num3 < 0.1f)
							{
								b = this.startingFeetOffset;
							}
							else if (num3 < 0.4f)
							{
								b = Vector3.Lerp(this.startingFeetOffset, vector, (num3 - 0.1f) / 0.3f);
							}
							else
							{
								this.movedFeetFarEnough = true;
							}
						}
						this.playAreaPreviewTransform.position = this.pointedAtPosition + b;
						active = true;
					}
				}
				vector2 = raycastHit.point;
			}
			else
			{
				this.destinationReticleTransform.gameObject.SetActive(false);
				this.offsetReticleTransform.gameObject.SetActive(false);
				this.teleportArc.SetColor(this.pointerInvalidColor);
				this.pointerLineRenderer.startColor = this.pointerInvalidColor;
				this.pointerLineRenderer.endColor = this.pointerInvalidColor;
				this.invalidReticleTransform.gameObject.SetActive(!flag2);
				Vector3 toDirection = raycastHit.normal;
				float num4 = Vector3.Angle(raycastHit.normal, Vector3.up);
				if (num4 < 15f)
				{
					toDirection = Vector3.up;
				}
				this.invalidReticleTargetRotation = Quaternion.FromToRotation(Vector3.up, toDirection);
				this.invalidReticleTransform.rotation = Quaternion.Slerp(this.invalidReticleTransform.rotation, this.invalidReticleTargetRotation, 0.1f);
				float num5 = Vector3.Distance(raycastHit.point, this.player.hmdTransform.position);
				float num6 = Util.RemapNumberClamped(num5, this.invalidReticleMinScaleDistance, this.invalidReticleMaxScaleDistance, this.invalidReticleMinScale, this.invalidReticleMaxScale);
				this.invalidReticleScale.x = num6;
				this.invalidReticleScale.y = num6;
				this.invalidReticleScale.z = num6;
				this.invalidReticleTransform.transform.localScale = this.invalidReticleScale;
				this.pointedAtTeleportMarker = null;
				if (flag)
				{
					vector2 = raycastHit.point;
				}
				else
				{
					vector2 = this.teleportArc.GetArcPositionAtTime(this.teleportArc.arcDuration);
				}
				if (this.debugFloor)
				{
					this.floorDebugSphere.gameObject.SetActive(false);
					this.floorDebugLine.gameObject.SetActive(false);
				}
			}
			if (this.playAreaPreviewTransform != null)
			{
				this.playAreaPreviewTransform.gameObject.SetActive(active);
			}
			if (!this.showOffsetReticle)
			{
				this.offsetReticleTransform.gameObject.SetActive(false);
			}
			this.destinationReticleTransform.position = this.pointedAtPosition;
			this.invalidReticleTransform.position = vector2;
			this.onActivateObjectTransform.position = vector2;
			this.onDeactivateObjectTransform.position = vector2;
			this.offsetReticleTransform.position = vector2 - vector;
			this.reticleAudioSource.transform.position = this.pointedAtPosition;
			this.pointerLineRenderer.SetPosition(0, position);
			this.pointerLineRenderer.SetPosition(1, vector2);
		}

		// Token: 0x06002924 RID: 10532 RVA: 0x000EF200 File Offset: 0x000ED400
		private void FixedUpdate()
		{
			if (!this.visible)
			{
				return;
			}
			if (this.debugFloor)
			{
				TeleportArea x = this.pointedAtTeleportMarker as TeleportArea;
				if (x != null && this.floorFixupMaximumTraceDistance > 0f)
				{
					this.floorDebugSphere.gameObject.SetActive(true);
					this.floorDebugLine.gameObject.SetActive(true);
					Vector3 down = Vector3.down;
					down.x = 0.01f;
					RaycastHit raycastHit;
					if (Physics.Raycast(this.pointedAtPosition + 0.05f * down, down, out raycastHit, this.floorFixupMaximumTraceDistance, this.floorFixupTraceLayerMask))
					{
						this.floorDebugSphere.transform.position = raycastHit.point;
						this.floorDebugSphere.material.color = Color.green;
						this.floorDebugLine.startColor = Color.green;
						this.floorDebugLine.endColor = Color.green;
						this.floorDebugLine.SetPosition(0, this.pointedAtPosition);
						this.floorDebugLine.SetPosition(1, raycastHit.point);
					}
					else
					{
						Vector3 position = this.pointedAtPosition + down * this.floorFixupMaximumTraceDistance;
						this.floorDebugSphere.transform.position = position;
						this.floorDebugSphere.material.color = Color.red;
						this.floorDebugLine.startColor = Color.red;
						this.floorDebugLine.endColor = Color.red;
						this.floorDebugLine.SetPosition(0, this.pointedAtPosition);
						this.floorDebugLine.SetPosition(1, position);
					}
				}
			}
		}

		// Token: 0x06002925 RID: 10533 RVA: 0x000EF3A8 File Offset: 0x000ED5A8
		private void OnChaperoneInfoInitialized()
		{
			ChaperoneInfo instance = ChaperoneInfo.instance;
			if (instance.initialized && instance.roomscale)
			{
				if (this.playAreaPreviewTransform == null)
				{
					this.playAreaPreviewTransform = new GameObject("PlayAreaPreviewTransform").transform;
					this.playAreaPreviewTransform.parent = base.transform;
					Util.ResetTransform(this.playAreaPreviewTransform, true);
					this.playAreaPreviewCorner.SetActive(true);
					this.playAreaPreviewCorners = new Transform[4];
					this.playAreaPreviewCorners[0] = this.playAreaPreviewCorner.transform;
					this.playAreaPreviewCorners[1] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewCorners[0]);
					this.playAreaPreviewCorners[2] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewCorners[0]);
					this.playAreaPreviewCorners[3] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewCorners[0]);
					this.playAreaPreviewCorners[0].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewCorners[1].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewCorners[2].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewCorners[3].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewSide.SetActive(true);
					this.playAreaPreviewSides = new Transform[4];
					this.playAreaPreviewSides[0] = this.playAreaPreviewSide.transform;
					this.playAreaPreviewSides[1] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewSides[0]);
					this.playAreaPreviewSides[2] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewSides[0]);
					this.playAreaPreviewSides[3] = UnityEngine.Object.Instantiate<Transform>(this.playAreaPreviewSides[0]);
					this.playAreaPreviewSides[0].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewSides[1].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewSides[2].transform.parent = this.playAreaPreviewTransform;
					this.playAreaPreviewSides[3].transform.parent = this.playAreaPreviewTransform;
				}
				float playAreaSizeX = instance.playAreaSizeX;
				float playAreaSizeZ = instance.playAreaSizeZ;
				this.playAreaPreviewSides[0].localPosition = new Vector3(0f, 0f, 0.5f * playAreaSizeZ - 0.25f);
				this.playAreaPreviewSides[1].localPosition = new Vector3(0f, 0f, -0.5f * playAreaSizeZ + 0.25f);
				this.playAreaPreviewSides[2].localPosition = new Vector3(0.5f * playAreaSizeX - 0.25f, 0f, 0f);
				this.playAreaPreviewSides[3].localPosition = new Vector3(-0.5f * playAreaSizeX + 0.25f, 0f, 0f);
				this.playAreaPreviewSides[0].localScale = new Vector3(playAreaSizeX - 0.5f, 1f, 1f);
				this.playAreaPreviewSides[1].localScale = new Vector3(playAreaSizeX - 0.5f, 1f, 1f);
				this.playAreaPreviewSides[2].localScale = new Vector3(playAreaSizeZ - 0.5f, 1f, 1f);
				this.playAreaPreviewSides[3].localScale = new Vector3(playAreaSizeZ - 0.5f, 1f, 1f);
				this.playAreaPreviewSides[0].localRotation = Quaternion.Euler(0f, 0f, 0f);
				this.playAreaPreviewSides[1].localRotation = Quaternion.Euler(0f, 180f, 0f);
				this.playAreaPreviewSides[2].localRotation = Quaternion.Euler(0f, 90f, 0f);
				this.playAreaPreviewSides[3].localRotation = Quaternion.Euler(0f, 270f, 0f);
				this.playAreaPreviewCorners[0].localPosition = new Vector3(0.5f * playAreaSizeX - 0.25f, 0f, 0.5f * playAreaSizeZ - 0.25f);
				this.playAreaPreviewCorners[1].localPosition = new Vector3(0.5f * playAreaSizeX - 0.25f, 0f, -0.5f * playAreaSizeZ + 0.25f);
				this.playAreaPreviewCorners[2].localPosition = new Vector3(-0.5f * playAreaSizeX + 0.25f, 0f, -0.5f * playAreaSizeZ + 0.25f);
				this.playAreaPreviewCorners[3].localPosition = new Vector3(-0.5f * playAreaSizeX + 0.25f, 0f, 0.5f * playAreaSizeZ - 0.25f);
				this.playAreaPreviewCorners[0].localRotation = Quaternion.Euler(0f, 0f, 0f);
				this.playAreaPreviewCorners[1].localRotation = Quaternion.Euler(0f, 90f, 0f);
				this.playAreaPreviewCorners[2].localRotation = Quaternion.Euler(0f, 180f, 0f);
				this.playAreaPreviewCorners[3].localRotation = Quaternion.Euler(0f, 270f, 0f);
				this.playAreaPreviewTransform.gameObject.SetActive(false);
			}
		}

		// Token: 0x06002926 RID: 10534 RVA: 0x000EF8C4 File Offset: 0x000EDAC4
		private void HidePointer()
		{
			if (this.visible)
			{
				this.pointerHideStartTime = Time.time;
			}
			this.visible = false;
			if (this.pointerHand)
			{
				if (this.ShouldOverrideHoverLock())
				{
					if (this.originalHoverLockState)
					{
						this.pointerHand.HoverLock(this.originalHoveringInteractable);
					}
					else
					{
						this.pointerHand.HoverUnlock(null);
					}
				}
				this.loopingAudioSource.Stop();
				this.PlayAudioClip(this.pointerAudioSource, this.pointerStopSound);
			}
			this.teleportPointerObject.SetActive(false);
			this.teleportArc.Hide();
			foreach (TeleportMarkerBase teleportMarkerBase in this.teleportMarkers)
			{
				if (teleportMarkerBase != null && teleportMarkerBase.markerActive && teleportMarkerBase.gameObject != null)
				{
					teleportMarkerBase.gameObject.SetActive(false);
				}
			}
			this.destinationReticleTransform.gameObject.SetActive(false);
			this.invalidReticleTransform.gameObject.SetActive(false);
			this.offsetReticleTransform.gameObject.SetActive(false);
			if (this.playAreaPreviewTransform != null)
			{
				this.playAreaPreviewTransform.gameObject.SetActive(false);
			}
			if (this.onActivateObjectTransform.gameObject.activeSelf)
			{
				this.onActivateObjectTransform.gameObject.SetActive(false);
			}
			this.onDeactivateObjectTransform.gameObject.SetActive(true);
			this.pointerHand = null;
		}

		// Token: 0x06002927 RID: 10535 RVA: 0x000EFA50 File Offset: 0x000EDC50
		private void ShowPointer(Hand newPointerHand, Hand oldPointerHand)
		{
			if (!this.visible)
			{
				this.pointedAtTeleportMarker = null;
				this.pointerShowStartTime = Time.time;
				this.visible = true;
				this.meshFading = true;
				this.teleportPointerObject.SetActive(false);
				this.teleportArc.Show();
				foreach (TeleportMarkerBase teleportMarkerBase in this.teleportMarkers)
				{
					if (teleportMarkerBase.markerActive && teleportMarkerBase.ShouldActivate(this.player.feetPositionGuess))
					{
						teleportMarkerBase.gameObject.SetActive(true);
						teleportMarkerBase.Highlight(false);
					}
				}
				this.startingFeetOffset = this.player.trackingOriginTransform.position - this.player.feetPositionGuess;
				this.movedFeetFarEnough = false;
				if (this.onDeactivateObjectTransform.gameObject.activeSelf)
				{
					this.onDeactivateObjectTransform.gameObject.SetActive(false);
				}
				this.onActivateObjectTransform.gameObject.SetActive(true);
				this.loopingAudioSource.clip = this.pointerLoopSound;
				this.loopingAudioSource.loop = true;
				this.loopingAudioSource.Play();
				this.loopingAudioSource.volume = 0f;
			}
			if (oldPointerHand && this.ShouldOverrideHoverLock())
			{
				if (this.originalHoverLockState)
				{
					oldPointerHand.HoverLock(this.originalHoveringInteractable);
				}
				else
				{
					oldPointerHand.HoverUnlock(null);
				}
			}
			this.pointerHand = newPointerHand;
			if (this.visible && oldPointerHand != this.pointerHand)
			{
				this.PlayAudioClip(this.pointerAudioSource, this.pointerStartSound);
			}
			if (this.pointerHand)
			{
				this.pointerStartTransform = this.GetPointerStartTransform(this.pointerHand);
				if (this.pointerHand.currentAttachedObject != null)
				{
					this.allowTeleportWhileAttached = this.pointerHand.currentAttachedObject.GetComponent<AllowTeleportWhileAttachedToHand>();
				}
				this.originalHoverLockState = this.pointerHand.hoverLocked;
				this.originalHoveringInteractable = this.pointerHand.hoveringInteractable;
				if (this.ShouldOverrideHoverLock())
				{
					this.pointerHand.HoverLock(null);
				}
				this.pointerAudioSource.transform.SetParent(this.pointerStartTransform);
				this.pointerAudioSource.transform.localPosition = Vector3.zero;
				this.loopingAudioSource.transform.SetParent(this.pointerStartTransform);
				this.loopingAudioSource.transform.localPosition = Vector3.zero;
			}
		}

		// Token: 0x06002928 RID: 10536 RVA: 0x000EFCDC File Offset: 0x000EDEDC
		private void UpdateTeleportColors()
		{
			float num = Time.time - this.pointerShowStartTime;
			if (num > this.meshFadeTime)
			{
				this.meshAlphaPercent = 1f;
				this.meshFading = false;
			}
			else
			{
				this.meshAlphaPercent = Mathf.Lerp(0f, 1f, num / this.meshFadeTime);
			}
			foreach (TeleportMarkerBase teleportMarkerBase in this.teleportMarkers)
			{
				teleportMarkerBase.SetAlpha(this.fullTintAlpha * this.meshAlphaPercent, this.meshAlphaPercent);
			}
		}

		// Token: 0x06002929 RID: 10537 RVA: 0x000EFD70 File Offset: 0x000EDF70
		private void PlayAudioClip(AudioSource source, AudioClip clip)
		{
			source.clip = clip;
			source.Play();
		}

		// Token: 0x0600292A RID: 10538 RVA: 0x000EFD80 File Offset: 0x000EDF80
		private void PlayPointerHaptic(bool validLocation)
		{
			if (this.pointerHand.controller != null)
			{
				if (validLocation)
				{
					this.pointerHand.controller.TriggerHapticPulse(800, EVRButtonId.k_EButton_Axis0);
				}
				else
				{
					this.pointerHand.controller.TriggerHapticPulse(100, EVRButtonId.k_EButton_Axis0);
				}
			}
		}

		// Token: 0x0600292B RID: 10539 RVA: 0x000EFDD4 File Offset: 0x000EDFD4
		private void TryTeleportPlayer()
		{
			if (this.visible && !this.teleporting && this.pointedAtTeleportMarker != null && !this.pointedAtTeleportMarker.locked)
			{
				this.teleportingToMarker = this.pointedAtTeleportMarker;
				this.InitiateTeleportFade();
				this.CancelTeleportHint();
			}
		}

		// Token: 0x0600292C RID: 10540 RVA: 0x000EFE30 File Offset: 0x000EE030
		private void InitiateTeleportFade()
		{
			this.teleporting = true;
			this.currentFadeTime = this.teleportFadeTime;
			TeleportPoint teleportPoint = this.teleportingToMarker as TeleportPoint;
			if (teleportPoint != null && teleportPoint.teleportType == TeleportPoint.TeleportPointType.SwitchToNewScene)
			{
				this.currentFadeTime *= 3f;
				Teleport.ChangeScene.Send(this.currentFadeTime);
			}
			SteamVR_Fade.Start(Color.clear, 0f, false);
			SteamVR_Fade.Start(Color.black, this.currentFadeTime, false);
			this.headAudioSource.transform.SetParent(this.player.hmdTransform);
			this.headAudioSource.transform.localPosition = Vector3.zero;
			this.PlayAudioClip(this.headAudioSource, this.teleportSound);
			base.Invoke("TeleportPlayer", this.currentFadeTime);
		}

		// Token: 0x0600292D RID: 10541 RVA: 0x000EFF0C File Offset: 0x000EE10C
		private void TeleportPlayer()
		{
			this.teleporting = false;
			Teleport.PlayerPre.Send(this.pointedAtTeleportMarker);
			SteamVR_Fade.Start(Color.clear, this.currentFadeTime, false);
			TeleportPoint teleportPoint = this.teleportingToMarker as TeleportPoint;
			Vector3 a = this.pointedAtPosition;
			if (teleportPoint != null)
			{
				a = teleportPoint.transform.position;
				if (teleportPoint.teleportType == TeleportPoint.TeleportPointType.SwitchToNewScene)
				{
					teleportPoint.TeleportToScene();
					return;
				}
			}
			TeleportArea x = this.teleportingToMarker as TeleportArea;
			RaycastHit raycastHit;
			if (x != null && this.floorFixupMaximumTraceDistance > 0f && Physics.Raycast(a + 0.05f * Vector3.down, Vector3.down, out raycastHit, this.floorFixupMaximumTraceDistance, this.floorFixupTraceLayerMask))
			{
				a = raycastHit.point;
			}
			if (this.teleportingToMarker.ShouldMovePlayer())
			{
				Vector3 b = this.player.trackingOriginTransform.position - this.player.feetPositionGuess;
				this.player.trackingOriginTransform.position = a + b;
			}
			else
			{
				this.teleportingToMarker.TeleportPlayer(this.pointedAtPosition);
			}
			Teleport.Player.Send(this.pointedAtTeleportMarker);
		}

		// Token: 0x0600292E RID: 10542 RVA: 0x000F0058 File Offset: 0x000EE258
		private void HighlightSelected(TeleportMarkerBase hitTeleportMarker)
		{
			if (this.pointedAtTeleportMarker != hitTeleportMarker)
			{
				if (this.pointedAtTeleportMarker != null)
				{
					this.pointedAtTeleportMarker.Highlight(false);
				}
				if (hitTeleportMarker != null)
				{
					hitTeleportMarker.Highlight(true);
					this.prevPointedAtPosition = this.pointedAtPosition;
					this.PlayPointerHaptic(!hitTeleportMarker.locked);
					this.PlayAudioClip(this.reticleAudioSource, this.goodHighlightSound);
					this.loopingAudioSource.volume = this.loopingAudioMaxVolume;
				}
				else if (this.pointedAtTeleportMarker != null)
				{
					this.PlayAudioClip(this.reticleAudioSource, this.badHighlightSound);
					this.loopingAudioSource.volume = 0f;
				}
			}
			else if (hitTeleportMarker != null && Vector3.Distance(this.prevPointedAtPosition, this.pointedAtPosition) > 1f)
			{
				this.prevPointedAtPosition = this.pointedAtPosition;
				this.PlayPointerHaptic(!hitTeleportMarker.locked);
			}
		}

		// Token: 0x0600292F RID: 10543 RVA: 0x000F0164 File Offset: 0x000EE364
		public void ShowTeleportHint()
		{
			this.CancelTeleportHint();
			this.hintCoroutine = base.StartCoroutine(this.TeleportHintCoroutine());
		}

		// Token: 0x06002930 RID: 10544 RVA: 0x000F0180 File Offset: 0x000EE380
		public void CancelTeleportHint()
		{
			if (this.hintCoroutine != null)
			{
				foreach (Hand hand in this.player.hands)
				{
					ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_Axis0);
				}
				base.StopCoroutine(this.hintCoroutine);
				this.hintCoroutine = null;
			}
			base.CancelInvoke("ShowTeleportHint");
		}

		// Token: 0x06002931 RID: 10545 RVA: 0x000F01E4 File Offset: 0x000EE3E4
		private IEnumerator TeleportHintCoroutine()
		{
			float prevBreakTime = Time.time;
			float prevHapticPulseTime = Time.time;
			for (;;)
			{
				bool pulsed = false;
				foreach (Hand hand in this.player.hands)
				{
					bool flag = this.IsEligibleForTeleport(hand);
					bool flag2 = !string.IsNullOrEmpty(ControllerButtonHints.GetActiveHintText(hand, EVRButtonId.k_EButton_Axis0));
					if (flag)
					{
						if (!flag2)
						{
							ControllerButtonHints.ShowTextHint(hand, EVRButtonId.k_EButton_Axis0, "Teleport", true);
							prevBreakTime = Time.time;
							prevHapticPulseTime = Time.time;
						}
						if (Time.time > prevHapticPulseTime + 0.05f)
						{
							pulsed = true;
							hand.controller.TriggerHapticPulse(500, EVRButtonId.k_EButton_Axis0);
						}
					}
					else if (!flag && flag2)
					{
						ControllerButtonHints.HideTextHint(hand, EVRButtonId.k_EButton_Axis0);
					}
				}
				if (Time.time > prevBreakTime + 3f)
				{
					yield return new WaitForSeconds(3f);
					prevBreakTime = Time.time;
				}
				if (pulsed)
				{
					prevHapticPulseTime = Time.time;
				}
				yield return null;
			}
			yield break;
		}

		// Token: 0x06002932 RID: 10546 RVA: 0x000F0200 File Offset: 0x000EE400
		public bool IsEligibleForTeleport(Hand hand)
		{
			if (hand == null)
			{
				return false;
			}
			if (!hand.gameObject.activeInHierarchy)
			{
				return false;
			}
			if (hand.hoveringInteractable != null)
			{
				return false;
			}
			if (hand.noSteamVRFallbackCamera == null)
			{
				if (hand.controller == null)
				{
					return false;
				}
				if (hand.currentAttachedObject != null)
				{
					AllowTeleportWhileAttachedToHand component = hand.currentAttachedObject.GetComponent<AllowTeleportWhileAttachedToHand>();
					return component != null && component.teleportAllowed;
				}
			}
			return true;
		}

		// Token: 0x06002933 RID: 10547 RVA: 0x000F0298 File Offset: 0x000EE498
		private bool ShouldOverrideHoverLock()
		{
			return !this.allowTeleportWhileAttached || this.allowTeleportWhileAttached.overrideHoverLock;
		}

		// Token: 0x06002934 RID: 10548 RVA: 0x000F02C0 File Offset: 0x000EE4C0
		private bool WasTeleportButtonReleased(Hand hand)
		{
			if (!this.IsEligibleForTeleport(hand))
			{
				return false;
			}
			if (hand.noSteamVRFallbackCamera != null)
			{
				return Input.GetKeyUp(KeyCode.T);
			}
			return hand.controller.GetPressUp(4294967296UL);
		}

		// Token: 0x06002935 RID: 10549 RVA: 0x000F0300 File Offset: 0x000EE500
		private bool IsTeleportButtonDown(Hand hand)
		{
			if (!this.IsEligibleForTeleport(hand))
			{
				return false;
			}
			if (hand.noSteamVRFallbackCamera != null)
			{
				return Input.GetKey(KeyCode.T);
			}
			return hand.controller.GetPress(4294967296UL);
		}

		// Token: 0x06002936 RID: 10550 RVA: 0x000F0340 File Offset: 0x000EE540
		private bool WasTeleportButtonPressed(Hand hand)
		{
			if (!this.IsEligibleForTeleport(hand))
			{
				return false;
			}
			if (hand.noSteamVRFallbackCamera != null)
			{
				return Input.GetKeyDown(KeyCode.T);
			}
			return hand.controller.GetPressDown(4294967296UL);
		}

		// Token: 0x06002937 RID: 10551 RVA: 0x000F0380 File Offset: 0x000EE580
		private Transform GetPointerStartTransform(Hand hand)
		{
			if (hand.noSteamVRFallbackCamera != null)
			{
				return hand.noSteamVRFallbackCamera.transform;
			}
			return this.pointerHand.GetAttachmentTransform("Attach_ControllerTip");
		}

		// Token: 0x0400292B RID: 10539
		public LayerMask traceLayerMask;

		// Token: 0x0400292C RID: 10540
		public LayerMask floorFixupTraceLayerMask;

		// Token: 0x0400292D RID: 10541
		public float floorFixupMaximumTraceDistance = 1f;

		// Token: 0x0400292E RID: 10542
		public Material areaVisibleMaterial;

		// Token: 0x0400292F RID: 10543
		public Material areaLockedMaterial;

		// Token: 0x04002930 RID: 10544
		public Material areaHighlightedMaterial;

		// Token: 0x04002931 RID: 10545
		public Material pointVisibleMaterial;

		// Token: 0x04002932 RID: 10546
		public Material pointLockedMaterial;

		// Token: 0x04002933 RID: 10547
		public Material pointHighlightedMaterial;

		// Token: 0x04002934 RID: 10548
		public Transform destinationReticleTransform;

		// Token: 0x04002935 RID: 10549
		public Transform invalidReticleTransform;

		// Token: 0x04002936 RID: 10550
		public GameObject playAreaPreviewCorner;

		// Token: 0x04002937 RID: 10551
		public GameObject playAreaPreviewSide;

		// Token: 0x04002938 RID: 10552
		public Color pointerValidColor;

		// Token: 0x04002939 RID: 10553
		public Color pointerInvalidColor;

		// Token: 0x0400293A RID: 10554
		public Color pointerLockedColor;

		// Token: 0x0400293B RID: 10555
		public bool showPlayAreaMarker = true;

		// Token: 0x0400293C RID: 10556
		public float teleportFadeTime = 0.1f;

		// Token: 0x0400293D RID: 10557
		public float meshFadeTime = 0.2f;

		// Token: 0x0400293E RID: 10558
		public float arcDistance = 10f;

		// Token: 0x0400293F RID: 10559
		[Header("Effects")]
		public Transform onActivateObjectTransform;

		// Token: 0x04002940 RID: 10560
		public Transform onDeactivateObjectTransform;

		// Token: 0x04002941 RID: 10561
		public float activateObjectTime = 1f;

		// Token: 0x04002942 RID: 10562
		public float deactivateObjectTime = 1f;

		// Token: 0x04002943 RID: 10563
		[Header("Audio Sources")]
		public AudioSource pointerAudioSource;

		// Token: 0x04002944 RID: 10564
		public AudioSource loopingAudioSource;

		// Token: 0x04002945 RID: 10565
		public AudioSource headAudioSource;

		// Token: 0x04002946 RID: 10566
		public AudioSource reticleAudioSource;

		// Token: 0x04002947 RID: 10567
		[Header("Sounds")]
		public AudioClip teleportSound;

		// Token: 0x04002948 RID: 10568
		public AudioClip pointerStartSound;

		// Token: 0x04002949 RID: 10569
		public AudioClip pointerLoopSound;

		// Token: 0x0400294A RID: 10570
		public AudioClip pointerStopSound;

		// Token: 0x0400294B RID: 10571
		public AudioClip goodHighlightSound;

		// Token: 0x0400294C RID: 10572
		public AudioClip badHighlightSound;

		// Token: 0x0400294D RID: 10573
		[Header("Debug")]
		public bool debugFloor;

		// Token: 0x0400294E RID: 10574
		public bool showOffsetReticle;

		// Token: 0x0400294F RID: 10575
		public Transform offsetReticleTransform;

		// Token: 0x04002950 RID: 10576
		public MeshRenderer floorDebugSphere;

		// Token: 0x04002951 RID: 10577
		public LineRenderer floorDebugLine;

		// Token: 0x04002952 RID: 10578
		private LineRenderer pointerLineRenderer;

		// Token: 0x04002953 RID: 10579
		private GameObject teleportPointerObject;

		// Token: 0x04002954 RID: 10580
		private Transform pointerStartTransform;

		// Token: 0x04002955 RID: 10581
		private Hand pointerHand;

		// Token: 0x04002956 RID: 10582
		private Player player;

		// Token: 0x04002957 RID: 10583
		private TeleportArc teleportArc;

		// Token: 0x04002958 RID: 10584
		private bool visible;

		// Token: 0x04002959 RID: 10585
		private TeleportMarkerBase[] teleportMarkers;

		// Token: 0x0400295A RID: 10586
		private TeleportMarkerBase pointedAtTeleportMarker;

		// Token: 0x0400295B RID: 10587
		private TeleportMarkerBase teleportingToMarker;

		// Token: 0x0400295C RID: 10588
		private Vector3 pointedAtPosition;

		// Token: 0x0400295D RID: 10589
		private Vector3 prevPointedAtPosition;

		// Token: 0x0400295E RID: 10590
		private bool teleporting;

		// Token: 0x0400295F RID: 10591
		private float currentFadeTime;

		// Token: 0x04002960 RID: 10592
		private float meshAlphaPercent = 1f;

		// Token: 0x04002961 RID: 10593
		private float pointerShowStartTime;

		// Token: 0x04002962 RID: 10594
		private float pointerHideStartTime;

		// Token: 0x04002963 RID: 10595
		private bool meshFading;

		// Token: 0x04002964 RID: 10596
		private float fullTintAlpha;

		// Token: 0x04002965 RID: 10597
		private float invalidReticleMinScale = 0.2f;

		// Token: 0x04002966 RID: 10598
		private float invalidReticleMaxScale = 1f;

		// Token: 0x04002967 RID: 10599
		private float invalidReticleMinScaleDistance = 0.4f;

		// Token: 0x04002968 RID: 10600
		private float invalidReticleMaxScaleDistance = 2f;

		// Token: 0x04002969 RID: 10601
		private Vector3 invalidReticleScale = Vector3.one;

		// Token: 0x0400296A RID: 10602
		private Quaternion invalidReticleTargetRotation = Quaternion.identity;

		// Token: 0x0400296B RID: 10603
		private Transform playAreaPreviewTransform;

		// Token: 0x0400296C RID: 10604
		private Transform[] playAreaPreviewCorners;

		// Token: 0x0400296D RID: 10605
		private Transform[] playAreaPreviewSides;

		// Token: 0x0400296E RID: 10606
		private float loopingAudioMaxVolume;

		// Token: 0x0400296F RID: 10607
		private Coroutine hintCoroutine;

		// Token: 0x04002970 RID: 10608
		private bool originalHoverLockState;

		// Token: 0x04002971 RID: 10609
		private Interactable originalHoveringInteractable;

		// Token: 0x04002972 RID: 10610
		private AllowTeleportWhileAttachedToHand allowTeleportWhileAttached;

		// Token: 0x04002973 RID: 10611
		private Vector3 startingFeetOffset = Vector3.zero;

		// Token: 0x04002974 RID: 10612
		private bool movedFeetFarEnough;

		// Token: 0x04002975 RID: 10613
		private SteamVR_Events.Action chaperoneInfoInitializedAction;

		// Token: 0x04002976 RID: 10614
		public static SteamVR_Events.Event<float> ChangeScene = new SteamVR_Events.Event<float>();

		// Token: 0x04002977 RID: 10615
		public static SteamVR_Events.Event<TeleportMarkerBase> Player = new SteamVR_Events.Event<TeleportMarkerBase>();

		// Token: 0x04002978 RID: 10616
		public static SteamVR_Events.Event<TeleportMarkerBase> PlayerPre = new SteamVR_Events.Event<TeleportMarkerBase>();

		// Token: 0x04002979 RID: 10617
		private static Teleport _instance;
	}
}
